package com.cn.bio;

import java.io.*;
import java.net.Socket;

public class BIOClient {
    public static void main(String[] args) {
        BufferedReader br = null;
        BufferedWriter bw = null;
        Socket socket = null;

        try {
            socket = new Socket("127.0.0.1", 8888);
            br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
            bw = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
            System.out.println("准备向服务器写数据");

            bw.write("hello i am client \n");
            bw.flush();
            String line = br.readLine();
            System.out.println("收到了来自服务器的数据：" + line);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (br != null) br.close();
                if (bw != null) bw.close();
                if (socket != null) socket.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }
}
